package leetcode.median;

public class $36_isValidSudoku {
    public boolean isValidSudoku(char[][] board) {
        int[][] rowCheck = new int[9][10];
        int[][] colCheck = new int[9][10];
        int[][] boxCheck = new int[9][10];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') {
                    continue;
                }
                int curNumber = board[i][j] - '0';
                if (rowCheck[i][curNumber] == 1) {
                    return false;
                }
                rowCheck[i][curNumber] = 1;
                if (colCheck[j][curNumber] == 1) {
                    return false;
                }
                colCheck[j][curNumber] = 1;
                if (boxCheck[j / 3 + (i / 3) * 3][curNumber] == 1) {
                    return false;
                }
                boxCheck[j / 3 + (i / 3) * 3][curNumber] = 1;
            }
        }
        return true;
    }
}
